import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/Home.vue'
import Errorinfo from '@/components/common/Erro404.vue'
Vue.use(VueRouter)

const routes = [
  {path: '/',
  redirect:"/welcome",
  beforeEnter: (to, from, next) => {
   
   next("/Home")
  },},
  {path:"/welcome" ,name:'WelCome',component: () => import('@/views/WelCome.vue')},
  { path: '/errorinfo', name: 'Errorinfo', component: Errorinfo },
  { path: '/Home', name: 'Home', component: Home },
  { path: '/MusicSinger', name: 'MusicSinger', component: () => import('@/views/Singer.vue') },
  { path: '/MusicRanking', name: 'MusicRanking', component: () => import('@/views/Ranking.vue') },
  { path: '/MusicMine', name: 'MusicMine', component: () => import('@/views/Mine.vue') },
  { path: '/MusicSearchBox', name: 'MusicSearchBox', component: () => import('@/components/search/search_box.vue') },
  { path: '/MusicDetail', name: 'MusicDetail', component: () => import('@/components/common/detail.vue') },
  { path: '/MusicIndex', name: 'MusicIndex', component: () => import('@/components/singer_song/index.vue') },
  { path: '/MusicAlbumList', name: 'MusicAlbumList', component: () => import('@/components/common/album_list.vue') },
  { path: '/MusicSongsListMore', name: 'MusicSongsListMore', component: () => import('@/components/common/songs_List _more.vue') },
  { path: '/MusicMusicListMore', name: 'MusicMusicListMore', component: () => import('@/components/common/music_list_more.vue') },
  { path: '/VueMusicCommentArea', name: 'VueMusicCommentArea', component: () => import('@/components/player/comment_area.vue') },
  { path: '/VueMusicSongClass', name: 'VueMusicSongClass', component: () => import('@/components/common/song_class.vue') },
  { path: '/VueMusicPlaylistComment', name: 'VueMusicPlaylistComment', component: () => import('@/components/common/playList_comment.vue') },
  { path: '/VueMusicMinesingerlist', name: 'VueMusicMinesingerlist', component: () => import('@/components/mine/mineSingerList.vue') },
  {
    path:"/denglu",
    name:"DengLu",
    component:()=>import("@/views/DengLu"),
    props:true
  },
  {
    path:`/mv/:id`,
    name:"MV",
    meta:{hideNav:true},
    props:true,
    component:()=>import('@/components/video/MV.vue')
  },
  {
    path: '/video',
    name: 'Video',
    component: () => import('@/views/Video')
  },
  
 
]

const router = new VueRouter({
  mode:'hash',
  base:process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
 
  
  
  if (to.matched.length === 0) { //匹配前往的路由不存在
    from.name ? next({
      name: from.name
    }) : next('/errorinfo'); //判断此跳转路由的来源路由是否存在，存在的情况跳转到来源路由，否则跳转到404页面
  } else {
    next(); //如果匹配到正确跳转
  }
});

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
// 页面错误前往
export default router
